﻿using Demo.HangfireIntergation.Jobs;
using Volo.Abp.BackgroundWorkers;
using Volo.Abp;

namespace Demo.HangfireIntergation.HangfireExtensions
{
    public class BackgroundJobStartup : IOnApplicationInitialization
    {
        private readonly IBackgroundWorkerManager _backgroundWorkerManager;

        public BackgroundJobStartup(IBackgroundWorkerManager backgroundWorkerManager)
        {
            _backgroundWorkerManager = backgroundWorkerManager;
        }

        public void OnApplicationInitialization(ApplicationInitializationContext context)
        {
            throw new NotImplementedException();
        }

        public async Task OnApplicationInitializationAsync(ApplicationInitializationContext context)
        {
            Console.WriteLine("定时任务开启---------------");
            await _backgroundWorkerManager.AddAsync(context.ServiceProvider.GetRequiredService<MyLogWorker>());
            await _backgroundWorkerManager.AddAsync(context.ServiceProvider.GetRequiredService<MyJob1>());
        }
    }
}
